﻿using L6_RegionNavigation.NavigateToExistView.Models;
using Prism.Mvvm;
using Prism.Navigation.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace L6_RegionNavigation.NavigateToExistView.ViewModels
{
    public class PersonAttributeViewModel : BindableBase, IRegionAware
    {
        private Person _model;
        public Person Model
        {
            get => _model;
            set
            {
                SetProperty(ref _model, value);
            }
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            Person p = navigationContext.Parameters.GetValue<Person>("model");
            if (p == null) return false;

            return _model.Id == p.Id;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            Model = navigationContext.Parameters.GetValue<Person>("model");
        }
    }
}